<#include "/admin/public.html">
<div class="uk-layui-form">
    <form class="layui-form uk-form" action="/admin/grade/save.html" method="post">
    	<input type="hidden" name="filename">
    	<input type="hidden" name="fileurl" lay-verify="fileurl">
        <div class="layui-form-item">
            <label class="layui-form-label">等级</label>
            <div class="layui-input-inline">
                <input type="text" name="grade" id="grade"  lay-verify="required|number" class="layui-input" placeholder="请等级">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">积分分组</label>
            <div class="layui-input-inline">
                <input type="text" name="groups" id="groups"  lay-verify="required" class="layui-input" placeholder="请积分分组">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">分数区间</label>
            <div class="layui-input-inline">
                <input type="text" name="minimum" id="minimum"   lay-verify="required" class="layui-input" placeholder="请分数区间最小值">
            </div>
             <div class="layui-input-inline">
                <input type="text" name="maximum" id="maximum"   lay-verify="required|big" class="layui-input" placeholder="请分数区间区间最大值">
            </div>
        </div>
        <div class="layui-form-item">
		    <label class="layui-form-label">勋章</label>
		    <div class="layui-input-inline">
		    	<a class="layui-btn layui-btn-primary"  id="informationUploadButton"><i class="layui-icon">&#xe608;</i>新增勋章</a>
		    </div>
		  </div>
		  <div class="layui-form-item layui-hide" id="inforShow">
		    <label class="layui-form-label"></label>
		     <div class="layui-input-inline">
		    	<img id="showInfor" alt="" src=""  style="width:130px" >
		    </div>
		  </div>
        <div class="layui-form-button">
            <div class="layui-button-block">
                <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
<script>
var url = "/gradeupload";
    //表单验证提交
    layui.use('form', function() {
        var form = layui.form();
        form.render(); //更新全部
        form.verify({
      	  big: function(value, item){ 
          	if( parseInt(value) <= parseInt($("#minimum").val())) {
      	      return '区间最大值有误';
      	     }
      	  },
      	 fileurl: function(value, item){ 
           	if(value == "") {
       	      return '请上传勋章';
       	     }
       	  }
      	  
      	});
    });
    
  //上传初始化
    var uploader = new plupload.Uploader({
    	browse_button: 'informationUploadButton', //触发文件选择对话框的按钮，为那个元素id
    	url: "${base}" + url, //服务器端的上传页面地址
    	flash_swf_url: '${ctxStatic}/plupload/js//Moxie.swf', //swf文件，当需要使用swf方式进行上传时需要配置该参数
    	silverlight_xap_url: '${ctxStatic}/plupload/js/Moxie.xap', //silverlight文件，当需要使用silverlight方式进行上传时需要配置该参数
    	filters : {
    		mime_types :[ 
    			{ title : "Image files", extensions : "jpg,jpeg,png,gif" }, 
    		
    	 	],
    	 	max_file_size : '40mb',
    	},
    });
     
    //在实例对象上调用init()方法进行初始化
    uploader.init();
    //绑定各种事件，并在事件监听函数中做你想做的事
    uploader.bind('FilesAdded',function(uploader, files) {
    	$("#inforShow").removeClass("layui-hide");
    	$("#showInfor").attr("src","/images/loading-slide.gif");
    	uploader.start()
    	
    })

    //上传后回调
    uploader.bind('FileUploaded', function(uploader,UploadProgress, responseObject) {
    	var obj = $.parseJSON(responseObject.response);
    	$("#showInfor").attr("src","/res/gradeFile/" + obj.fileId +".html");
    	$("#showInfor").attr("alt",obj.fileName);
    	$("input[name=fileurl]").val(obj.fileId);
    	$("input[name=fileName]").val(obj.fileName)
    });

    //报错
    uploader.bind('Error',function(up,err) {
    	 if(err.code == '-600'){
    		 layer.msg('文件最多可上传40M', {icon: 5});
          }	
    	
    });
</script>